package mo.tags.backtrack;

import java.util.ArrayList;
import java.util.List;

public class L491 {

    public List<List<Integer>> findSubsequences(int[] nums) {
        List<List<Integer>> res = new ArrayList<>();
        List<Integer> combination = new ArrayList<>();
        dfs(res, combination, nums, 0, Integer.MIN_VALUE);
        return res;
    }

    private void dfs(List<List<Integer>> res, List<Integer> combination, int[] nums, int idx, int last) {
        if (idx == nums.length) {
            if (combination.size() >= 2) {
                res.add(new ArrayList<>(combination));
            }
            return;
        }
        if (nums[idx] >= last) {
            combination.add(nums[idx]);
            dfs(res, combination, nums, idx+1, nums[idx]);
            combination.remove(combination.size()-1);
        }
        if (nums[idx] != last) {
            dfs(res, combination, nums, idx+1, last);
        }
    }

    public static void main(String[] args) {
        L491 test = new L491();
        System.out.println(test.findSubsequences(new int[]{4,6,7,7}));
    }

}
